package 算法练习;

public class Jun9记录 {
    public static void main(String[] args) {
//        int[] ints = Solution.twoSum(new int[]{3, 2, 4}, 6);
//        for (int i:ints){
//            System.out.println(i);
//        }

        Solution.deleteNode(new ListNode(5));
    }
}

class ListNode {

  int val;

  ListNode next;


    ListNode(int x) {
        val = x;
    }

    @Override
    public String toString() {
        return "ListNode{" +
                "val=" + val +
                ", next=" + next +
                '}';
    }
}

class Solution {
    public static int[] twoSum(int[] nums, int target) {
        int[] index = new int[2];
        for (int i=0;i<nums.length;i++){
            for (int j=i+1;j<nums.length;j++){
                if (nums[i]+nums[j]==target){
                    index[0]=i;
                    index[1]=j;
                    return index;
                }
            }
        }
        return null;
    }

    public int strStr(String haystack, String needle) {
        char[] chars1 = haystack.toCharArray();
        char[] chars2 = needle.toCharArray();
        for (int i=0;i<chars1.length;i=i+chars2.length){
            if (chars1[i] == chars2[0]){

            }
        }
        return 0;
    }
    //4->5->1->9

    public static void deleteNode(ListNode node) {
        ListNode head = new ListNode(0);
        ListNode l1 = new ListNode(4);
        ListNode l2 = new ListNode(5);
        ListNode l3 = new ListNode(1);
        ListNode l4 = new ListNode(9);
        head.next = l1;
        l1.next = l2;
        l2.next = l3;
        l3.next = l4;
        ListNode temp = head;
        boolean flag = false;
        while (true){
            if (temp.next == null){
                break;
            }
            if (temp.next.val == node.val){
                flag = true;
                break;
            }
            temp = temp.next;

        }
        if (flag){
            temp.next = temp.next.next;
        }
    }
}
